trade2011[,1:196] <- lapply(trade2011[,1:196], as.numeric)
dis2011 <- read.csv("dis2011.csv", header=T, row.names=1)
dis2011[,1:196] <- lapply(dis2011[,1:196], as.numeric)
# For node attributes (GDP, democracy, military expenditure) of 2011
load("vcov3.RData")
attri2011 <- subset(vcov3, year==2011,
select=state: log_military)
net2011 <- network(as.matrix(Edge2011), directed = T)
set.vertex.attribute(net2011,names(attri2011),attri2011)
set.network.attribute(net2011,"ally2011",as.matrix(ally2011))
set.network.attribute(net2011,"FDI2011",as.matrix(FDI2011))
set.network.attribute(net2011,"trade2011",as.matrix(trade2011))
set.network.attribute(net2011,"dis2011",as.matrix(dis2011))
# Network 2010====
Edge2010 <- read.csv("Edge2010.csv", header=T, row.names=1)
ally2010 <- read.csv("ally2010.csv", header=T, row.names=1)
ally2010[,1:196] <- lapply(ally2010[,1:196], as.numeric)
FDI2010 <- read.csv("FDI2010.csv", header=T, row.names=1)
FDI2010[,1:196] <- lapply(FDI2010[,1:196], as.numeric)
trade2010 <- read.csv("trade2010.csv", header=T, row.names=1)
trade2010[,1:196] <- lapply(trade2010[,1:196], as.numeric)
dis2010 <- read.csv("dis2010.csv", header=T, row.names=1)
dis2010[,1:196] <- lapply(dis2010[,1:196], as.numeric)
# For node attributes (GDP, democracy, military expenditure) of 2010
load("vcov3.RData")
attri2010 <- subset(vcov3, year==2010,
select=state: log_military)
net2010 <- network(as.matrix(Edge2010), directed = T)
set.vertex.attribute(net2010,names(attri2010),attri2010)
set.network.attribute(net2010,"ally2010",as.matrix(ally2010))
set.network.attribute(net2010,"FDI2010",as.matrix(FDI2010))
set.network.attribute(net2010,"trade2010",as.matrix(trade2010))
set.network.attribute(net2010,"dis2010",as.matrix(dis2010))
# Network 2009====
Edge2009 <- read.csv("Edge2009.csv", header=T, row.names=1)
ally2009 <- read.csv("ally2009.csv", header=T, row.names=1)
ally2009[,1:196] <- lapply(ally2009[,1:196], as.numeric)
FDI2009 <- read.csv("FDI2009.csv", header=T, row.names=1)
FDI2009[,1:196] <- lapply(FDI2009[,1:196], as.numeric)
trade2009 <- read.csv("trade2009.csv", header=T, row.names=1)
trade2009[,1:196] <- lapply(trade2009[,1:196], as.numeric)
dis2009 <- read.csv("dis2009.csv", header=T, row.names=1)
dis2009[,1:196] <- lapply(dis2009[,1:196], as.numeric)
# For node attributes (GDP, democracy, military expenditure) of 2009
load("vcov3.RData")
attri2009 <- subset(vcov3, year==2009,
select=state: log_military)
net2009 <- network(as.matrix(Edge2009), directed = T)
set.vertex.attribute(net2009,names(attri2009),attri2009)
set.network.attribute(net2009,"ally2009",as.matrix(ally2009))
set.network.attribute(net2009,"FDI2009",as.matrix(FDI2009))
set.network.attribute(net2009,"trade2009",as.matrix(trade2009))
set.network.attribute(net2009,"dis2009",as.matrix(dis2009))
##### Now Using BTERGM to do the same thing
networks <- list()# create network object
networks[[1]] <- net2010
networks[[2]] <- net2011
networks[[3]] <- net2012
networks[[4]] <- net2013
networks[[5]] <- net2014
networks[[6]] <- net2015
networks[[7]] <- net2016
networks[[8]] <- net2017
networks[[9]] <- net2018
# Set network attributes
network.vertex.names(x=net2009) <- attri2009$state
network.vertex.names(x=net2010) <- attri2010$state
network.vertex.names(x=net2011) <- attri2011$state
network.vertex.names(x=net2012) <- attri2012$state
network.vertex.names(x=net2013) <- attri2013$state
network.vertex.names(x=net2014) <- attri2014$state
network.vertex.names(x=net2015) <- attri2015$state
network.vertex.names(x=net2016) <- attri2016$state
network.vertex.names(x=net2017) <- attri2017$state
network.vertex.names(x=net2018) <- attri2018$state
LagNet<-list()
LagNet[[1]] <- net2009      # add network to the list
LagNet[[2]] <- net2010
LagNet[[3]] <- net2011
LagNet[[4]] <- net2012
LagNet[[5]] <- net2013
LagNet[[6]] <- net2014
LagNet[[7]] <- net2015
LagNet[[8]] <- net2016
LagNet[[9]] <- net2017
FDI2009<-network(as.matrix(FDI2009),matrix.type="a",
ignore.eval=FALSE,names.eval="weight", directed = T)
FDI2010<-network(as.matrix(FDI2010),matrix.type="a",
ignore.eval=FALSE,names.eval="weight", directed = T)
FDI2011<-network(as.matrix(FDI2011),matrix.type="a",
ignore.eval=FALSE,names.eval="weight", directed = T)
FDI2012<-network(as.matrix(FDI2012),matrix.type="a",
ignore.eval=FALSE,names.eval="weight", directed = T)
FDI2013<-network(as.matrix(FDI2013),matrix.type="a",
ignore.eval=FALSE,names.eval="weight", directed = T)
FDI2014<-network(as.matrix(FDI2014),matrix.type="a",
ignore.eval=FALSE,names.eval="weight", directed = T)
FDI2015<-network(as.matrix(FDI2015),matrix.type="a",
ignore.eval=FALSE,names.eval="weight", directed = T)
FDI2016<-network(as.matrix(FDI2016),matrix.type="a",
ignore.eval=FALSE,names.eval="weight", directed = T)
FDI2017<-network(as.matrix(FDI2017),matrix.type="a",
ignore.eval=FALSE,names.eval="weight", directed = T)
FDI2018<-network(as.matrix(FDI2018),matrix.type="a",
ignore.eval=FALSE,names.eval="weight", directed = T)
# FDI2010<-network(as.matrix(FDI2010), directed = T)
# FDI2011<-network(as.matrix(FDI2011), directed = T)
# FDI2012<-network(as.matrix(FDI2012), directed = T)
# FDI2013<-network(as.matrix(FDI2013), directed = T)
# FDI2014<-network(as.matrix(FDI2014), directed = T)
# FDI2015<-network(as.matrix(FDI2015), directed = T)
# FDI2016<-network(as.matrix(FDI2016), directed = T)
# FDI2017<-network(as.matrix(FDI2017), directed = T)
# FDI2018<-network(as.matrix(FDI2018), directed = T)
# Set network attributes
network.vertex.names(x=FDI2009) <- attri2009$state
network.vertex.names(x=FDI2010) <- attri2010$state
network.vertex.names(x=FDI2011) <- attri2011$state
network.vertex.names(x=FDI2012) <- attri2012$state
network.vertex.names(x=FDI2013) <- attri2013$state
network.vertex.names(x=FDI2014) <- attri2014$state
network.vertex.names(x=FDI2015) <- attri2015$state
network.vertex.names(x=FDI2016) <- attri2016$state
network.vertex.names(x=FDI2017) <- attri2017$state
network.vertex.names(x=FDI2018) <- attri2018$state
FDINet<-list()
FDINet[[1]] <- FDI2009
FDINet[[2]] <- FDI2010
FDINet[[3]] <- FDI2011
FDINet[[4]] <- FDI2012
FDINet[[5]] <- FDI2013
FDINet[[6]] <- FDI2014
FDINet[[7]] <- FDI2015
FDINet[[8]] <- FDI2016
FDINet[[9]] <- FDI2017
# For ally
ally2009<-network(as.matrix(ally2009), directed = F)
ally2010<-network(as.matrix(ally2010), directed = F)
ally2011<-network(as.matrix(ally2011), directed = F)
ally2012<-network(as.matrix(ally2012), directed = F)
ally2013<-network(as.matrix(ally2013), directed = F)
ally2014<-network(as.matrix(ally2014), directed = F)
ally2015<-network(as.matrix(ally2015), directed = F)
ally2016<-network(as.matrix(ally2016), directed = F)
ally2017<-network(as.matrix(ally2017), directed = F)
ally2018<-network(as.matrix(ally2018), directed = F)
# Set network attributes
network.vertex.names(x=ally2009) <- attri2009$state
network.vertex.names(x=ally2010) <- attri2010$state
network.vertex.names(x=ally2011) <- attri2011$state
network.vertex.names(x=ally2012) <- attri2012$state
network.vertex.names(x=ally2013) <- attri2013$state
network.vertex.names(x=ally2014) <- attri2014$state
network.vertex.names(x=ally2015) <- attri2015$state
network.vertex.names(x=ally2016) <- attri2016$state
network.vertex.names(x=ally2017) <- attri2017$state
network.vertex.names(x=ally2018) <- attri2018$state
allyNet<-list()
allyNet[[1]] <-ally2010
allyNet[[2]] <-ally2011
allyNet[[3]] <-ally2012
allyNet[[4]] <-ally2013
allyNet[[5]] <-ally2014
allyNet[[6]] <-ally2015
allyNet[[7]] <-ally2016
allyNet[[8]] <-ally2017
allyNet[[9]] <-ally2018
# For trade
trade2009<-network(as.matrix(trade2009),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_trade", directed = T)
trade2010<-network(as.matrix(trade2010),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_trade", directed = T)
trade2011<-network(as.matrix(trade2011),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_trade", directed = T)
trade2012<-network(as.matrix(trade2012),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_trade", directed = T)
trade2013<-network(as.matrix(trade2013),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_trade", directed = T)
trade2014<-network(as.matrix(trade2014),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_trade", directed = T)
trade2015<-network(as.matrix(trade2015),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_trade", directed = T)
trade2016<-network(as.matrix(trade2016),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_trade", directed = T)
trade2017<-network(as.matrix(trade2017),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_trade", directed = T)
trade2018<-network(as.matrix(trade2018),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_trade", directed = T)
# Set network attributes
network.vertex.names(x=trade2009) <- attri2009$state
network.vertex.names(x=trade2010) <- attri2010$state
network.vertex.names(x=trade2011) <- attri2011$state
network.vertex.names(x=trade2012) <- attri2012$state
network.vertex.names(x=trade2013) <- attri2013$state
network.vertex.names(x=trade2014) <- attri2014$state
network.vertex.names(x=trade2015) <- attri2015$state
network.vertex.names(x=trade2016) <- attri2016$state
network.vertex.names(x=trade2017) <- attri2017$state
network.vertex.names(x=trade2018) <- attri2018$state
#
tradeNet<-list()
tradeNet[[1]] <- trade2009
tradeNet[[2]] <- trade2010
tradeNet[[3]] <- trade2011
tradeNet[[4]] <- trade2012
tradeNet[[5]] <- trade2013
tradeNet[[6]] <- trade2014
tradeNet[[7]] <- trade2015
tradeNet[[8]] <- trade2016
tradeNet[[9]] <- trade2017
# For distance
dis2009<-network(as.matrix(dis2009),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_distance", directed = T)
dis2010<-network(as.matrix(dis2010),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_distance", directed = T)
dis2011<-network(as.matrix(dis2011),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_distance", directed = T)
dis2012<-network(as.matrix(dis2012),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_distance", directed = T)
dis2013<-network(as.matrix(dis2013),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_distance", directed = T)
dis2014<-network(as.matrix(dis2014),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_distance", directed = T)
dis2015<-network(as.matrix(dis2015),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_distance", directed = T)
dis2016<-network(as.matrix(dis2016),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_distance", directed = T)
dis2017<-network(as.matrix(dis2017),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_distance", directed = T)
dis2018<-network(as.matrix(dis2018),matrix.type="a",
ignore.eval=FALSE,names.eval="weight_distance", directed = T)
# Set network attributes
network.vertex.names(x=dis2009) <- attri2009$state
network.vertex.names(x=dis2010) <- attri2010$state
network.vertex.names(x=dis2011) <- attri2011$state
network.vertex.names(x=dis2012) <- attri2012$state
network.vertex.names(x=dis2013) <- attri2013$state
network.vertex.names(x=dis2014) <- attri2014$state
network.vertex.names(x=dis2015) <- attri2015$state
network.vertex.names(x=dis2016) <- attri2016$state
network.vertex.names(x=dis2017) <- attri2017$state
network.vertex.names(x=dis2018) <- attri2018$state
disNet<-list()
disNet[[1]] <-dis2010
disNet[[2]] <-dis2011
disNet[[3]] <-dis2012
disNet[[4]] <-dis2013
disNet[[5]] <-dis2014
disNet[[6]] <-dis2015
disNet[[7]] <-dis2016
disNet[[8]] <-dis2017
disNet[[9]] <-dis2018
# set overall network attributes
# the folowing command is to make sure values are numeric:
# attri2016[,2:4] <- lapply(attri2016[,2:4], as.numeric)
# attri2017[,2:4] <- lapply(attri2017[,2:4], as.numeric)
# attri2018[,2:4] <- lapply(attri2018[,2:4], as.numeric)
set.vertex.attribute(networks[[1]],"attri", attri2010)
set.vertex.attribute(networks[[2]],"attri", attri2011)
set.vertex.attribute(networks[[3]],"attri", attri2012)
set.vertex.attribute(networks[[4]],"attri", attri2013)
set.vertex.attribute(networks[[5]],"attri", attri2014)
set.vertex.attribute(networks[[6]],"attri", attri2015)
set.vertex.attribute(networks[[7]],"attri", attri2016)
set.vertex.attribute(networks[[8]],"attri", attri2017)
set.vertex.attribute(networks[[9]],"attri", attri2018)
set.seed(1234)
#
fit2 <- btergm(networks ~
edgecov(FDINet, attrname="weight")
+edgecov(LagNet)
+edgecov(tradeNet,attrname="weight_trade")
+edgecov(disNet, attrname="weight_distance")
+edgecov(allyNet)
+ edges+ istar(2) + ostar(2) + mutual + ttriple + ctriple
+nodeicov("log_military")
+nodeicov("mean_Democracy")
+nodeocov("log_GDP")
+absdiff("mean_Democracy")
+absdiff("log_GDP")
+absdiff("log_military")
+isolates,
R = 1000)
summary(fit2)
alldyads2 <- edgeprob(fit2)
model <- glm(probability ~ edgecov.weight, family = "binomial", data = alldyads2)
# Create a data frame for predictions
new_data <- alldyads2 %>%
mutate(pred = predict(model, newdata = ., type = "response"),
se = predict(model, newdata = ., type = "link", se.fit = TRUE)$se.fit) %>%
mutate(lower = pred - 1.96 * se,  # Lower bound of 95% CI
upper = pred + 1.96 * se)  # Upper bound of 95% CI
# Plot with ggplot2
ggplot(new_data, aes(x = edgecov.weight, y = pred)) +
geom_line(color = "blue") +                                # Main line
geom_line(aes(y = lower), linetype = "dashed", color = "black") +  # Lower bound
geom_line(aes(y = upper), linetype = "dashed", color = "black") +  # Upper bound
labs(y = "Probability of Cosponsorship", x = "FDI (log)") +
theme_minimal()+
theme(
axis.title.x = element_text(size = 24),  # X-axis label size
axis.title.y = element_text(size = 24),  # Y-axis label size
axis.text.x = element_text(size = 24),   # X-axis numbers (ticks) size
axis.text.y = element_text(size = 24)    # Y-axis numbers (ticks) size
)
# Get the effect of trade
model <- glm(probability ~ edgecov.weight_trade, family = "binomial", data = alldyads2)
# Create a data frame for predictions
new_data <- alldyads2 %>%
mutate(pred = predict(model, newdata = ., type = "response"),
se = predict(model, newdata = ., type = "link", se.fit = TRUE)$se.fit) %>%
mutate(lower = pred - 1.96 * se,  # Lower bound of 95% CI
upper = pred + 1.96 * se)  # Upper bound of 95% CI
# Plot with ggplot2
ggplot(new_data, aes(x = edgecov.weight_trade, y = pred)) +
geom_line(color = "blue") +                                # Main line
geom_line(aes(y = lower), linetype = "dashed", color = "black") +  # Lower bound
geom_line(aes(y = upper), linetype = "dashed", color = "black") +  # Upper bound
labs(y = "Probability of Cosponsorship", x = "Trade (log)") +
theme_minimal()+
theme(
axis.title.x = element_text(size = 24),  # X-axis label size
axis.title.y = element_text(size = 24),  # Y-axis label size
axis.text.x = element_text(size = 24),   # X-axis numbers (ticks) size
axis.text.y = element_text(size = 24)    # Y-axis numbers (ticks) size
)
library(magick)
img1 <- image_read("Upper left.png") %>% image_border("white", "20x20")
img2 <- image_read("Upper right.png") %>% image_border("white", "20x20")
img3 <- image_read("Lower left.png") %>% image_border("white", "20x20")
img4 <- image_read("Lower right.png") %>% image_border("white", "20x20")
# Combine images in rows with space
row1 <- image_append(c(img1, img2), stack = FALSE)
row2 <- image_append(c(img3, img4), stack = FALSE)
# Stack the two rows with space
final_image <- image_append(c(row1, row2), stack = TRUE)
final_image
# Define the target width and height
target_width <- 400   # Change as needed
target_height <- 300  # Change as needed
# Read and resize images to ensure they have the same dimensions
img1 <- image_read("Upper left.png") %>% image_resize(paste0(target_width, "x", target_height))
img2 <- image_read("Upper right.png") %>% image_resize(paste0(target_width, "x", target_height))
img3 <- image_read("Lower left.png") %>% image_resize(paste0(target_width, "x", target_height))
img4 <- image_read("Lower right.png") %>% image_resize(paste0(target_width, "x", target_height))
# Add spacing by adding borders
border_size <- "20x20"
img1 <- image_border(img1, "white", border_size)
img2 <- image_border(img2, "white", border_size)
img3 <- image_border(img3, "white", border_size)
img4 <- image_border(img4, "white", border_size)
# Combine images in two rows
row1 <- image_append(c(img1, img2), stack = FALSE)
row2 <- image_append(c(img3, img4), stack = FALSE)
# Stack the two rows together
final_image <- image_append(c(row1, row2), stack = TRUE)
final_image
alldyads2 <- edgeprob(fit2)
model <- glm(probability ~ edgecov.weight, family = "binomial", data = alldyads2)
# Create a data frame for predictions
new_data <- alldyads2 %>%
mutate(pred = predict(model, newdata = ., type = "response"),
se = predict(model, newdata = ., type = "link", se.fit = TRUE)$se.fit) %>%
mutate(lower = pred - 1.96 * se,  # Lower bound of 95% CI
upper = pred + 1.96 * se)  # Upper bound of 95% CI
# Plot with ggplot2
ggplot(new_data, aes(x = edgecov.weight, y = pred)) +
geom_line(color = "blue") +                                # Main line
geom_line(aes(y = lower), linetype = "dashed", color = "black") +  # Lower bound
geom_line(aes(y = upper), linetype = "dashed", color = "black") +  # Upper bound
labs(y = "Probability of Cosponsorship", x = "FDI (log)",caption =
"The effect of FDI of Model 2") +
theme_minimal()+
theme(
axis.title.x = element_text(size = 24),  # X-axis label size
axis.title.y = element_text(size = 24),  # Y-axis label size
axis.text.x = element_text(size = 24),   # X-axis numbers (ticks) size
axis.text.y = element_text(size = 24)    # Y-axis numbers (ticks) size
)
# Plot with ggplot2
ggplot(new_data, aes(x = edgecov.weight, y = pred)) +
geom_line(color = "blue") +                                # Main line
geom_line(aes(y = lower), linetype = "dashed", color = "black") +  # Lower bound
geom_line(aes(y = upper), linetype = "dashed", color = "black") +  # Upper bound
labs(y = "Probability of Cosponsorship", x = "FDI (log)",caption =
"The effect of FDI of Model 2") +
theme_minimal()+
theme(
axis.title.x = element_text(size = 24),  # X-axis label size
axis.title.y = element_text(size = 24),  # Y-axis label size
axis.text.x = element_text(size = 24),   # X-axis numbers (ticks) size
axis.text.y = element_text(size = 24),    # Y-axis numbers (ticks) size
plot.caption = element_text(size = 24, face = "bold", hjust = 0.5)  # Bigger, centered caption
)
model <- glm(probability ~ edgecov.weight_trade, family = "binomial", data = alldyads2)
# Create a data frame for predictions
new_data <- alldyads2 %>%
mutate(pred = predict(model, newdata = ., type = "response"),
se = predict(model, newdata = ., type = "link", se.fit = TRUE)$se.fit) %>%
mutate(lower = pred - 1.96 * se,  # Lower bound of 95% CI
upper = pred + 1.96 * se)  # Upper bound of 95% CI
# Plot with ggplot2
ggplot(new_data, aes(x = edgecov.weight_trade, y = pred)) +
geom_line(color = "blue") +                                # Main line
geom_line(aes(y = lower), linetype = "dashed", color = "black") +  # Lower bound
geom_line(aes(y = upper), linetype = "dashed", color = "black") +  # Upper bound
labs(y = "Probability of Cosponsorship", x = "Trade (log)",caption =
"The effect of trade of Model 2") +
theme_minimal()+
theme(
axis.title.x = element_text(size = 24),  # X-axis label size
axis.title.y = element_text(size = 24),  # Y-axis label size
axis.text.x = element_text(size = 24),   # X-axis numbers (ticks) size
axis.text.y = element_text(size = 24),    # Y-axis numbers (ticks) size
plot.caption = element_text(size = 24, face = "bold", hjust = 0.5)  # Bigger, centered caption
)
gof2<-gof(fit2, control=control.gof.ergm(nsim=1000))
plot(gof2)
setwd("~/Desktop/submission/FDI Networks/International Interaction/Third Revision-1:31:25/Replication 2")
library(magick)
# put them together
# Define the target width and height
target_width <- 400   # Change as needed
target_height <- 300  # Change as needed
# Read and resize images to ensure they have the same dimensions
img1 <- image_read("image1.png") %>% image_resize(paste0(target_width, "x", target_height))
img2 <- image_read("image2.png") %>% image_resize(paste0(target_width, "x", target_height))
img3 <- image_read("image3.png") %>% image_resize(paste0(target_width, "x", target_height))
img4 <- image_read("image4.png") %>% image_resize(paste0(target_width, "x", target_height))
# Add spacing by adding borders
border_size <- "20x20"
img1 <- image_border(img1, "white", border_size)
img2 <- image_border(img2, "white", border_size)
img3 <- image_border(img3, "white", border_size)
img4 <- image_border(img4, "white", border_size)
# Combine images in two rows
row1 <- image_append(c(img1, img2), stack = FALSE)
row2 <- image_append(c(img3, img4), stack = FALSE)
# Stack the two rows together
final_image <- image_append(c(row1, row2), stack = TRUE)
final_image
setwd("~/Desktop/submission/FDI Networks/International Interaction/Third Revision-1:31:25/Replication Materials")
library("writexl")
library(plyr)
library(dplyr)
library(tidyverse)
library(haven)
library(countrycode)
library(igraph)
library(ergm)
library(btergm)
library(readxl)
library(tibble)
library(ggplot2)
sp2009 <- read.csv("Edge2009.csv",row.names=1)
sp2010 <- read.csv("Edge2010.csv",row.names=1)
sp2011 <- read.csv("Edge2011.csv",row.names=1)
sp2012 <- read.csv("Edge2012.csv",row.names=1)
sp2013 <- read.csv("Edge2013.csv",row.names=1)
sp2014 <- read.csv("Edge2014.csv",row.names=1)
sp2015 <- read.csv("Edge2015.csv",row.names=1)
sp2016 <- read.csv("Edge2016.csv",row.names=1)
sp2017 <- read.csv("Edge2017.csv",row.names=1)
sp2018 <- read.csv("Edge2018.csv",row.names=1)
g2009 <- graph.adjacency(as.matrix(sp2009), mode="directed",weighted=NULL)
g2010 <- graph.adjacency(as.matrix(sp2010), mode="directed",weighted=NULL)
g2011 <- graph.adjacency(as.matrix(sp2011), mode="directed",weighted=NULL)
g2012 <- graph.adjacency(as.matrix(sp2012), mode="directed",weighted=NULL)
g2013 <- graph.adjacency(as.matrix(sp2013), mode="directed",weighted=NULL)
g2014 <- graph.adjacency(as.matrix(sp2014), mode="directed",weighted=NULL)
g2015 <- graph.adjacency(as.matrix(sp2015), mode="directed",weighted=NULL)
g2016 <- graph.adjacency(as.matrix(sp2016), mode="directed",weighted=NULL)
g2017 <- graph.adjacency(as.matrix(sp2017), mode="directed",weighted=NULL)
g2018 <- graph.adjacency(as.matrix(sp2018), mode="directed",weighted=NULL)
# number of nodes
number_states <- c(vcount(g2009), vcount(g2010), vcount(g2011), vcount(g2012), vcount(g2013), vcount(g2014),
vcount(g2015), vcount(g2016), vcount(g2017), vcount(g2018))
number_isolates <- c(sum(degree(g2009)==0), sum(degree(g2010)==0), sum(degree(g2011)==0),
sum(degree(g2012)==0), sum(degree(g2013)==0), sum(degree(g2014)==0),
sum(degree(g2015)==0), sum(degree(g2016)==0), sum(degree(g2017)==0),sum(degree(g2018)==0))
number_isolates
number_ties <- c(ecount(g2009), ecount(g2010), ecount(g2011), ecount(g2012), ecount(g2013), ecount(g2014),
ecount(g2015), ecount(g2016), ecount(g2017),ecount(g2018))
number_ties
density <- c(graph.density(g2009), graph.density(g2010), graph.density(g2011), graph.density(g2012),
graph.density(g2013), graph.density(g2014), graph.density(g2015), graph.density(g2016),
graph.density(g2017),graph.density(g2018))
density
sym_dyads <- c(1-(dyad.census(g2009)$asym/(vcount(g2009)*(vcount(g2009)-1)/2)),
1-(dyad.census(g2010)$asym/(vcount(g2010)*(vcount(g2010)-1)/2)),
1-(dyad.census(g2011)$asym/(vcount(g2011)*(vcount(g2011)-1)/2)),
1-(dyad.census(g2012)$asym/(vcount(g2012)*(vcount(g2012)-1)/2)),
1-(dyad.census(g2013)$asym/(vcount(g2013)*(vcount(g2013)-1)/2)),
1-(dyad.census(g2014)$asym/(vcount(g2014)*(vcount(g2014)-1)/2)),
1-(dyad.census(g2015)$asym/(vcount(g2015)*(vcount(g2015)-1)/2)),
1-(dyad.census(g2016)$asym/(vcount(g2016)*(vcount(g2016)-1)/2)),
1-(dyad.census(g2017)$asym/(vcount(g2017)*(vcount(g2017)-1)/2)),
1-(dyad.census(g2018)$asym/(vcount(g2018)*(vcount(g2018)-1)/2)))
sym_dyads
# global clustering coefficient
clustering <- c(transitivity(g2009), transitivity(g2010), transitivity(g2011), transitivity(g2012),
transitivity(g2013), transitivity(g2014), transitivity(g2015), transitivity(g2016),
transitivity(g2017),transitivity(g2018))
clustering
my_nested_list = list(number_isolates,
number_ties,
density,
sym_dyads,
clustering)
dfdescr <-  as.data.frame(do.call(rbind, my_nested_list))
rownames(dfdescr) <- c("isolates","ties","density","sym_dyads","clustering")
dfdescr
